﻿using System;
using System.Collections.Generic;
using System.Text;
using FutSA.Data;
using FutSA.Bussiness.Contexts;

namespace FutSA.Bussiness.Helpers
{
    /// <summary>
    /// Classe responsável pela administração de todas as exceções.
    /// </summary>
    public class ExceptionManager
    {
        #region Methods
        #region Static
		public static bool RegisterException(Exception exception)
        {
            try
            {
                FutSA.Bussiness.Contexts.Error error = new Error();
                FutSADataSet.ErrorRow errorRow = error.DataSet.Error.NewErrorRow();
                errorRow.Dia = DateTime.Now;
                errorRow.ErrorData = exception.Message;
                errorRow.ErrorType = "Normal";
                errorRow.UserID = 0;
                error.DataSet.Error.AddErrorRow(errorRow);
                error.Update(error.DataSet);

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public static bool RegisterException(Exception exception, int userID)
        {
            try
            {
                FutSA.Bussiness.Contexts.Error error = new Error();
                FutSADataSet.ErrorRow errorRow = error.DataSet.Error.NewErrorRow();
                errorRow.Dia = DateTime.Now;
                errorRow.ErrorData = exception.Message;
                errorRow.ErrorType = "Normal";
                errorRow.UserID = userID;
                error.DataSet.Error.AddErrorRow(errorRow);
                error.Update(error.DataSet);

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        public static bool RegisterException(Exception exception,  string errorType)
        {
            try
            {
                RegisterException(exception, 0, errorType);  
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        
        public static bool RegisterException(Exception exception, int userID, string errorType)
        {
            try
            {
                FutSA.Bussiness.Contexts.Error error = new Error();
                FutSADataSet.ErrorRow errorRow = error.DataSet.Error.NewErrorRow();
                errorRow.Dia = DateTime.Now;
                errorRow.ErrorData = exception.Message;
                errorRow.ErrorType = errorType;
                errorRow.UserID = userID;
                error.DataSet.Error.AddErrorRow(errorRow);
                error.Update(error.DataSet);

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

	    #endregion
	    #endregion    
    }
}
